package com.yq.backend.pojo;


/**
 * 统一返回对象
 */

import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

@Data
@ToString
public class Result<T> implements Serializable {

    /**
     * 返回状态码
     */
    private int code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 数据类型
     */
    private T data;

    /**
     * 总页数
     */
    private long total;


    public static <T> Result<T> success( String msg) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg(msg);
        return result;
    }



    public static <T> Result<T> success(long total, Object obj) {
        Result result = new Result();
        result.setCode(200);
        result.setTotal(total);
        result.setMsg("success");
        result.setData(obj);
        return result;
    }
    public static Result success() {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("success");
        return result;
    }

    public static <T> Result<T> success(Object obj) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("success");
        result.setData(obj);
        return result;
    }

    public static Result error() {
        Result result = new Result();
        result.setCode(500);
        result.setMsg("系统异常");
        return result;
    }


    public static Result<Object> noResult() {
        Result result = new Result();
        result.setCode(502);
        result.setMsg("查询无结果");
        return result;
    }

    public static Result errorParameter() {
        Result result = new Result();
        result.setCode(501);
        result.setMsg("请求参数错误");
        return result;
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result success(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


    public void setCode(int code) {
        this.code = code;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getTotal() {
        return total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }




}
